package cn.vpclub.admin.web.home;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "video")
public class VideoStream {
    public static VideoCapture videoCapture;
    Logger logger = LoggerFactory.getLogger(VideoStream.class);

    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    @RequestMapping(value = "readVideo")
    public Mat readVideo() {
        videoCapture = new VideoCapture();
        Mat mat = null;
        boolean opened = videoCapture.open("D:\\1.mp4");
        System.out.println("opened" + opened);
        if (!opened) {
            logger.error("视频打开失败");
        } else {
            mat = new Mat();
            logger.info("视频打开成功");
            boolean read = videoCapture.read(mat);
            logger.info(mat.toString());
//            while (true) {
//                Mat mat = new Mat();
//                boolean read = videoCapture.read(mat);
//                logger.info(String.valueOf(mat));
////                System.out.println("opened--" + opened + "---read--" + read + "--empty--" + mat.empty());
////                if (mat.empty()) {
////                    break;
////                }
////                HighGui.imshow("读取本地mp4视频", mat);
////                HighGui.waitKey(25);
//            }
//            videoCapture.release();
//            HighGui.destroyAllWindows();
        }
        return mat;
    }
}
